var oTable;
var modal;
var ProjectProgress = function() {
	var editable = function() {
		return {
			init : function() {
				oTable = $('#modelEditable_comm').dataTable(
								{
									"autoWidth" : false,
								 	"bPaginate" : false, // 是否显示分页
									"bLengthChange" : false, // 每页显示的记录数
									"lengthMenu" : [ [ 10, 15, 20, 50, -1 ],
											[ 10, 15, 20, 50, "All" ] ],
									"displayLength": 10,
									"language" : {
										"lengthMenu" : "每页 _MENU_ 条记录",
										"paginate" : {
											"previous" : "上一页",
											"next" : "下一页"
										},
										"info" : "",
										"sInfoEmpty": "",
										"infoEmpty" : "", //记录数为0",
										"sZeroRecords" : "找不到相关数据"
									},
									"columnDefs" : [ {
										"data" : null,
										"sortable" : false,
										"defaultContent" : "<center>-</center>",
										"targets" : [ 0 ]
									}, {
										"data" : null,
										"sortable" : false,
										"defaultContent" : "<center>-</center>",
										"targets" : [ 1 ]
									}, {
										"data" : null,
										"sortable" : false,
										"defaultContent" : "<center>-</center>",
										"targets" : [ 2 ]
									}, {
										"data" : null,
										"sortable" : false,
										"defaultContent" : "<center>-</center>",
										"targets" : [ 3 ]
									}, {
										"data" : null,
										"sortable" : false,
										"defaultContent" : "<center>-</center>",
										"targets" : [ 4]
									} ],
									"columns" : [ {
										"data" : "createTime"
									}, {
										"data" : "employeeName"
									}, {
										"data" : "roleType"
									}, {
										"data" : "result"
									}, {
										"data" : "suggestion"
									} ],
									"filter" : false,
									"processing" : false,
									"serverSide" : true,
									"ajaxSource" : ctx
											+ "/project/projectprogress",
									"serverMethod" : "post",
									"fnRowCallback" : function(nRow, aData,displayIndex) {
										nRow.children[0].id = aData.employeeId;
										var roleType = aData.roleType
										var roleName ="";
										switch(roleType)
										{
										case 1:
											roleName = "投资部";
										  break;
										case 2:
											roleName = "尽调小组";
										  break;
										case 3:
											roleName = "项目初审委员会";
										  break;
										case 4:
											roleName = "项目决策委员会";
										  break;
										case 5:
											roleName = "法律合规部";
										  break;
										case 6:
											roleName = "项目最终审批人";
										  break;
										case 7:
											roleName = "资金运用决策委员会";
										  break;
										case 8:
											roleName = "资金运用最终审批人";
										  break;
										case 9:
											roleName = "产品部人员";
										  break;
										default:
										}
										$('td:eq(2)', nRow).html(roleName);
										var result = aData.result;
										switch(result)
										{
										case 1:
											$('td:eq(3)', nRow).html("同意");
										  break;
										case 2:
											$('td:eq(3)', nRow).html("不同意");
										  break;
										case 2:
											$('td:eq(3)', nRow).html("弃权");
										  break;
										default:
										}
										return nRow;
									},
									"fnServerData" : function(ajaxSource,
											dataSet, fnCallback) {
										var start;
										var pageSize;
										for (var i = 0; i < dataSet.length; i++) {
											s = dataSet[i];
											if (s.name == 'iDisplayStart') {
												start = s.value;
											} else if (s.name == 'iDisplayLength') {
												pageSize = s.value;
											}
										}
										var id = $("#projectId").val();
										$.ajax({
													"contentType" : "application/json; charset=UTF-8",
													"dataType" : 'json',
													"type" : "POST",
													"url" : ajaxSource,
													"data" : '{"id":"'
															+ $("#projectId").val()
															+ '","start":'
															+ start
															+ ',"pageSize":'
															+ pageSize + "}",
													"success" : fnCallback
												});
									},
								});

			}

		};

	}();

	return {
		init : function() {
			editable.init();
		}
	};
}();

var ProjectReport = function() {
	var editable = function() {
		return {
			init : function() {
				oTableReport = $('#modelEditable_report').dataTable(
								{
				                	"autoWidth": false,
				                	"bPaginate" : false, // 是否显示分页
									"bLengthChange" : false, // 每页显示的记录数
				                	"lengthMenu": [
				                        [10, 15, 20, 50, -1],
				                        [10, 15, 20, 50, "All"]
				                    ],
				                    "displayLength": 10,
				                    "language": {
				                        "lengthMenu": "每页 _MENU_ 条记录",
				                        "paginate": {
				                            "previous": "上一页",
				                            "next": "下一页"
				                        },
				                        "info" : "",
				                        "sInfoEmpty": "",
				                        "infoEmpty" : "记录数为0",
				                    },
				                    'sortable': false,
				                    "columnDefs": [
										{
										    "data": null,
										    'sortable': false,
										    "defaultContent": "",
										    "targets": [0]
										},
										{
										    "data": null,
										    'sortable': false,
										    "defaultContent": "-",
										    "targets": [1]
										},
										{
										    "data": null,
										    'sortable': false,
										    "defaultContent": "-",
										    "targets": [2]
										}
				                    ],
				                    "columns": [
				                        { "data": "typeName" },
				                        { "data": "approveRoleNum" },
				                        { "data": "employeeId" },
				                   ],
				                   "filter" : false,
				                   "processing": false,
				                   "serverSide": true,
				                   "ajaxSource": ctx + "/approveRoleGroup/queryRole",
				                   "serverMethod": "post",
				                   "fnRowCallback" : function(nRow, aData, displayIndex) {
				                	   nRow.children[0].id = aData.approveRoleGroupId;
				                	   nRow.children[0].empId = aData.employeeId;
				                	   $('td:eq(0)', nRow).html(aData.empName);
				                	   $('td:eq(1)', nRow).html(aData.empMobile);
				                	   if(aData.isPrincipal){
				                		   $('td:eq(2)', nRow).html('是');
				                	   }else{
				                		   $('td:eq(2)', nRow).html('否');
				                	   }
				                       return nRow;
				                   },
				                   "fnServerData" : function(ajaxSource, dataSet, fnCallback) {
					                   var json = "{";
					                   var s;
					                   for (var i = 0; i < dataSet.length; i++) {
					                       s = dataSet[i];
					                   	   if (s.name == 'sEcho') {
					                   		   json = json + '"echo":' + s.value;
						                   } else if (s.name == 'iDisplayStart') {
						                	   json = json + ',"start":' + s.value;
						                   } else if (s.name == 'iDisplayLength') {
						                	   json = json + ',"pageSize":' + s.value;
						                   }
					                   }
					                   var id=$("#report_group_id").val();
					                   var employeeId=$("#group_capital_id").val();
					                   json=json+",\"id\":\""+id+"\",\"employeeId\":\""+employeeId+"\"}";
				                       $.ajax({
				                       	"contentType":"application/json; charset=UTF-8",
				                           "dataType" : 'json',
				                           "type" : "POST",
				                           "url" : ajaxSource,
				                           "data" : json,
				                           "success" : fnCallback
				                       });
				                   },
				                });
			}

		};

	}();

	return {
		init : function() {
			editable.init();
		}
	};
}();

var ProjectContract = function() {
	var editable = function() {
		return {
			init : function() {
				oTableContract = $('#modelEditable_contract').dataTable(
								{
									"autoWidth" : false,
									"bPaginate" : false, // 是否显示分页
									"bLengthChange" : false, // 每页显示的记录数
									"lengthMenu" : [ [ 10, 15, 20, 50 ],
											[ 10, 15, 20, 50 ] ],
									"displayLength" : 10,
									"language" : {
										"lengthMenu" : "每页 _MENU_ 条记录",
										"paginate" : {
											"previous" : "上一页",
											"next" : "下一页"
										},
										"info" :  "",
										"sInfoEmpty": "",
										"sZeroRecords" : "找不到相关数据"
									},
									"columnDefs" : [ {
										"data" : null,
										"sortable" : false,
										"defaultContent" : "<center>-</center>",
										"targets" : [ 0 ]
									}, {
										"data" : null,
										"sortable" : false,
										"defaultContent" : "<center>-</center>",
										"targets" : [ 1 ]
									}, {
										"data" : null,
										"sortable" : false,
										"defaultContent" : "<center>-</center>",
										"targets" : [ 2 ]
									} ],
									"columns" : [ {
										"data" : "contractName"
									}, {
										"data" : "employeeName"
									}, {
										"data" : "createTime"
									}],
									"filter" : false,
									"processing" : false,
									"serverSide" : true,
									"ajaxSource" : ctx
											+ "/project/projectReport",
									"serverMethod" : "post",
									"fnRowCallback" : function(nRow, aData,displayIndex) {
										nRow.children[0].id = aData.id;
										nRow.children[0].name = aData.contractName;
										var roleType = aData.roleType
										return nRow;
									},
									"fnServerData" : function(ajaxSource,dataSet, fnCallback) {
										var start;
										var pageSize;
										for (var i = 0; i < dataSet.length; i++) {
											s = dataSet[i];
											if (s.name == 'iDisplayStart') {
												start = s.value;
											} else if (s.name == 'iDisplayLength') {
												pageSize = s.value;
											}
										}
										$.ajax({
													"contentType" : "application/json; charset=UTF-8",
													"dataType" : 'json',
													"type" : "POST",
													"url" : ajaxSource,
													"data" : '{"projectId":"'
															+ $("#projectId").val()
															+ '","start":'
															+ start
															+ ',"type":'
															+ 3
															+ ',"pageSize":'
															+ pageSize + "}",
													"success" : fnCallback
												});
									},
								});
			}

		};

	}();

	return {
		init : function() {
			editable.init();
		}
	};
}();

var gradeArray = new Array();
gradeArray[1]="☆";
gradeArray[2]="★";
gradeArray[3]="★☆";
gradeArray[4]="★★";
gradeArray[5]="★★☆";
gradeArray[6]="★★★";
gradeArray[7]="★★★☆";
gradeArray[8]="★★★★";
gradeArray[9]="★★★★☆";
gradeArray[10]="★★★★★";
var ProjectGrade = function() {
	var editable = function() {
		return {
			init : function() {
				oTableGrade = $('#modelEditabl_grade').dataTable(
								{
									"autoWidth" : false,
									"bPaginate" : false, // 是否显示分页
									"bLengthChange" : false, // 每页显示的记录数
									"lengthMenu" : [ [ 10, 15, 20, 50, -1 ],
											[ 10, 15, 20, 50, "All" ] ],
									"displayLength" : 10,
									"language" : {
										"lengthMenu" : "每页 _MENU_ 条记录",
										"paginate" : {
											"previous" : "上一页",
											"next" : "下一页"
										},
										"info" :  "",
										"sInfoEmpty": "",
										"sZeroRecords" : "找不到相关数据"
									},
									"columnDefs" : [ {
										"data" : null,
										"sortable" : false,
										"defaultContent" : "<center>-</center>",
										"targets" : [ 0 ]
									}, {
										"data" : null,
										"sortable" : false,
										"defaultContent" : "<center>-</center>",
										"targets" : [ 1 ]
									}, {
										"data" : null,
										"sortable" : false,
										"defaultContent" : "<center>-</center>",
										"targets" : [ 2 ]
									}, {
										"data" : null,
										"sortable" : false,
										"defaultContent" : "<center>-</center>",
										"targets" : [ 3 ]
									} ],
									"columns" : [ {
										"data" : "grade"
									}, {
										"data" : "employeeName"
									}, {
										"data" : "fileList"
									}, {
										"data" : "time"
									}],
									"filter" : false,
									"processing" : false,
									"serverSide" : true,
									"ajaxSource" : ctx
											+ "/project/projectGrade",
									"serverMethod" : "post",
									"fnRowCallback" : function(nRow, aData,displayIndex) {
										nRow.children[0].id = aData.id;
										nRow.children[0].name = aData.contractName;
										var roleType = aData.roleType
										var time = aData.time;
										$('td:eq(0)', nRow).html(gradeArray[aData.grade]);
										$('td:eq(3)', nRow).html(time.substring(0,16));
										return nRow;
									},
									"fnServerData" : function(ajaxSource,dataSet, fnCallback) {
										var start;
										var pageSize;
										for (var i = 0; i < dataSet.length; i++) {
											s = dataSet[i];
											if (s.name == 'iDisplayStart') {
												start = s.value;
											} else if (s.name == 'iDisplayLength') {
												pageSize = s.value;
											}
										}
										$.ajax({
													"contentType" : "application/json; charset=UTF-8",
													"dataType" : 'json',
													"type" : "POST",
													"url" : ajaxSource,
													"data" : '{"projectId":"'
															+ $("#projectId").val()
															+ '","start":'
															+ start
															+ ',"type":'
															+ 3
															+ ',"pageSize":'
															+ pageSize + "}",
													"success" : fnCallback
												});
									},
								});
			}

		};

	}();

	return {
		init : function() {
			editable.init();
		}
	};
}();

var ProjectAsset = function() {
	var editable = function() {
		return {
			init : function() {
				oTableGrade = $('#modelEditable_asset').dataTable(
								{
									"autoWidth" : false,
									"bPaginate" : false, // 是否显示分页
									"bLengthChange" : false, // 每页显示的记录数
									"lengthMenu" : [ [ 10, 15, 20, 50, -1 ],
											[ 10, 15, 20, 50, "All" ] ],
									"displayLength" : 10,
									"language" : {
										"lengthMenu" : "每页 _MENU_ 条记录",
										"paginate" : {
											"previous" : "上一页",
											"next" : "下一页"
										},
										"info" :  "",
										"sInfoEmpty": "",
										"sZeroRecords" : "找不到相关数据"
									},
									"columnDefs" : [ {
										"data" : null,
										"sortable" : false,
										"defaultContent" : "<center>-</center>",
										"targets" : [ 0 ]
									}, {
										"data" : null,
										"sortable" : false,
										"defaultContent" : "<center>-</center>",
										"targets" : [ 1 ]
									}, {
										"data" : null,
										"sortable" : false,
										"defaultContent" : "<center>-</center>",
										"targets" : [ 2 ]
									}, {
										"data" : null,
										"sortable" : false,
										"defaultContent" : "<center>-</center>",
										"targets" : [ 3 ]
									}, {
										"data" : null,
										"sortable" : false,
										"defaultContent" : "<center>-</center>",
										"targets" : [ 4 ]
									} ],
									"columns" : [ {
										"data" : "productName"
									}, {
										"data" : "amount"
									}, {
										"data" : "assetName"
									}, {
										"data" : "state"
									}, {
										"data" : "createTime"
									}],
									"filter" : false,
									"processing" : false,
									"serverSide" : true,
									"ajaxSource" : ctx
											+ "/project/projectAsset",
									"serverMethod" : "post",
									"fnRowCallback" : function(nRow, aData,displayIndex) {
										nRow.children[0].id = aData.id;
										nRow.children[0].name = aData.contractName;
										var state = aData.state
										var stateStr = "-";
										if(state == 1){
											stateStr = "待审批";
										}else if(state == 2){
											stateStr = "审批中";
										}else if(state == 3){
											stateStr = "终审中";
										}else if(state == 4){
											stateStr = "过终审";
										}else if(state == 5){
											stateStr = "已投资";
										}
										$('td:eq(3)', nRow).html(stateStr);
										return nRow;
									},
									"fnServerData" : function(ajaxSource,dataSet, fnCallback) {
										var start;
										var pageSize;
										for (var i = 0; i < dataSet.length; i++) {
											s = dataSet[i];
											if (s.name == 'iDisplayStart') {
												start = s.value;
											} else if (s.name == 'iDisplayLength') {
												pageSize = s.value;
											}
										}
										$.ajax({
													"contentType" : "application/json; charset=UTF-8",
													"dataType" : 'json',
													"type" : "POST",
													"url" : ajaxSource,
													"data" : '{"projectId":"'
															+ $("#projectId").val()
															+ '","start":'
															+ start
															+ ',"type":'
															+ 3
															+ ',"pageSize":'
															+ pageSize + "}",
													"success" : fnCallback
												});
									},
								});
			}

		};

	}();

	return {
		init : function() {
			editable.init();
		}
	};
}();